﻿using System;
using System.Collections.Generic;
using System.Data;
using Ue.Infrastructure.DomainBase;
using Ue.Infrastructure.RepositoryFramework.Repository;
using Ue.Qcdz.Domain.TheSiteConfig;

namespace Ue.Qcdz.Repositories.TheSiteConfig
{
    public class SiteConfigRepository : SqlServerRepository<SiteConfig>,ISiteConfigRepository
    {
        #region Overrides of SqlServerRepositoryBase<SiteConfig>

        protected override string GetDataTableName()
        {
            return "TheSiteConfig";
        }

        protected override string[] GetBaseInsertFields()
        {
            return new string[]
                       {
                           SiteConfigFactory.FieldNames.EntityKey,
                           SiteConfigFactory.FieldNames.Complaint,
                           SiteConfigFactory.FieldNames.Contact,
                           SiteConfigFactory.FieldNames.Copyright,
                           SiteConfigFactory.FieldNames.CopyrightEn,
                           SiteConfigFactory.FieldNames.Email,
                           SiteConfigFactory.FieldNames.Record,
                           SiteConfigFactory.FieldNames.SiteName,
                           SiteConfigFactory.FieldNames.MetaKeyworld,
                           SiteConfigFactory.FieldNames.MetaDescription
                       };
        }

        protected override string[] GetBaseUpdateFields()
        {
            return new string[]
                       {
                           SiteConfigFactory.FieldNames.Complaint,
                           SiteConfigFactory.FieldNames.Contact,
                           SiteConfigFactory.FieldNames.Copyright,
                           SiteConfigFactory.FieldNames.CopyrightEn,
                           SiteConfigFactory.FieldNames.Email,
                           SiteConfigFactory.FieldNames.Record,
                           SiteConfigFactory.FieldNames.SiteName,
                           SiteConfigFactory.FieldNames.MetaKeyworld,
                           SiteConfigFactory.FieldNames.MetaDescription
                       };
        }

        protected override IDataParameter[] BuildParameters(SiteConfig entity)
        {
            return new IDataParameter[]
                       {
                           RepositoryDriver.BuildParameter(SiteConfigFactory.FieldNames.EntityKey,entity.Key),
                           RepositoryDriver.BuildParameter(SiteConfigFactory.FieldNames.Complaint,entity.Complaint),
                           RepositoryDriver.BuildParameter(SiteConfigFactory.FieldNames.Contact,entity.Contact),
                           RepositoryDriver.BuildParameter(SiteConfigFactory.FieldNames.Copyright,entity.Copyright),
                           RepositoryDriver.BuildParameter(SiteConfigFactory.FieldNames.CopyrightEn,entity.CopyrightEn),
                           RepositoryDriver.BuildParameter(SiteConfigFactory.FieldNames.Email,entity.Email),
                           RepositoryDriver.BuildParameter(SiteConfigFactory.FieldNames.Record,entity.Record),
                           RepositoryDriver.BuildParameter(SiteConfigFactory.FieldNames.SiteName,entity.SiteName),
                           RepositoryDriver.BuildParameter(SiteConfigFactory.FieldNames.MetaKeyworld,entity.MetaKeyworld),
                           RepositoryDriver.BuildParameter(SiteConfigFactory.FieldNames.MetaDescription,entity.MetaDescription)
                       };
        }

        protected override IWhereClause BuildWhereClauseBy(IDataQuery dataQuery)
        {
            return null;
        }

        protected override IDictionary<string, ChildDataHandler> GetBuildEntityChildCallbacks()
        {
            return null;
        }

        #endregion

        #region Implementation of ISiteConfigRepository

        public SiteConfig FindBy()
        {
            var query = "SELECT TOP 1 * FROM TheSiteConfig";
            return this.BuildEntityFromSql(query);
        }

        #endregion
    }
}
